package kz.pompei.ifacer.clipboard;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class WidgetTransfer implements java.awt.datatransfer.Transferable {
  public final static DataFlavor FLAVOR = new DataFlavor(WidgetSelection.class, "Selected widgets");
  private final WidgetSelection selection;
  
  public WidgetTransfer(WidgetSelection selection) {
    this.selection = selection;
  }
  
  @Override
  public DataFlavor[] getTransferDataFlavors() {
    return new DataFlavor[] { FLAVOR };
  }
  
  @Override
  public boolean isDataFlavorSupported(DataFlavor flavor) {
    return FLAVOR.equals(flavor);
  }
  
  @Override
  public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (isDataFlavorSupported(flavor)) return selection;
    throw new UnsupportedFlavorException(flavor);
  }
  
}
